import time

import Common

class applog:
    db=""
    cursor=""
    db,cursor=Common.connectMysql()
    def weishi(self):
        sqlTable="weishi_log_info"
        Common.createSqlTable(self.db, self.cursor, sqlTable)
        while True:
            f=Common.getStream()
            logs=Common.readTxt(f)
            f.seek(2)
            if logs=="":
                continue
            Common.getlogsLevelAndWirteMysql(self.db,self.cursor,sqlTable,logs)
            time.sleep(2)
        f.close()
        Common.closeConnectMysql(self.db, self.cursor)

    def now(self):
        sqlTable = "now_log_info"
        Common.createSqlTable(self.db, self.cursor, sqlTable)
        while True:
            f = Common.getStream()
            logs = Common.readTxt(f)
            f.seek(2)
            if logs == "":
                continue
            Common.getlogsLevelAndWirteMysql(self.db, self.cursor, sqlTable, logs)
            time.sleep(2)
        f.close()
        Common.closeConnectMysql(self.db,self.cursor)

if __name__ == '__main__':
    applog().weishi()
    # applog().now()